package com.xl.basic.controller;

import com.xl.basic.annotation.RoleValidated;
import com.xl.basic.entity.Result;
import com.xl.basic.entity.UserInfo;
import com.xl.basic.entity.param.AddRoleUserParam;
import com.xl.basic.entity.param.DelRoleUserParam;
import com.xl.basic.service.RoleUserService;
import com.xl.basic.utils.LoginUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 钟勇
 * Create in 2023/8/31 10:19
 */

@Tag(name = "角色用户管理")
@RestController
@RequestMapping("/api/RoleUser")
@RequiredArgsConstructor
@RoleValidated
public class RoleUserController {
    private final RoleUserService roleUserService;

    @Operation(summary = "添加角色用户")
    @PostMapping(value = "/addRoleUser")
    Result<Object> addRoleUser(@Validated AddRoleUserParam param) {
        Result<UserInfo> userInfo = LoginUtils.getUserInfo();
        return roleUserService.addRoleUser(param, userInfo.getResult());
    }


    @Operation(summary = "删除角色用户")
    @PostMapping(value = "/delRoleUser")
    Result<Object> delRoleUser(@Validated DelRoleUserParam param) {
        Result<UserInfo> userInfo = LoginUtils.getUserInfo();
        return roleUserService.delRoleUser(param, userInfo.getResult());
    }

}
